﻿using Furion.DatabaseAccessor;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Builders;
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Furion.CMS.Domain
{
    /// <summary>
    /// 数据字典类别
    /// </summary>
    public class DataDictionaryCategory : IEntity, IEntityTypeBuilder<DataDictionaryCategory>
    {
        public DataDictionaryCategory()
        {
            CreatedTime = DateTimeOffset.UtcNow;
            Dictionaries = new HashSet<DataDictionary>();
        }

        /// <summary>
        /// 类别Id
        /// </summary>
        public Guid Id { get; set; }
        /// <summary>
        /// 类别名称
        /// </summary>
        [MaxLength(200), Required]
        public string Name { get; set; }
        /// <summary>
        /// 类别描述
        /// </summary>
        [MaxLength(400)]
        public string Description { get; set; }
        /// <summary>
        /// 排序号
        /// </summary>
        public int SortNumber { get; set; }
        /// <summary>
        /// 创建时间
        /// </summary>
        public DateTimeOffset CreatedTime { get; set; }

        /// <summary>
        /// 数据键值集合
        /// </summary>
        public virtual ICollection<DataDictionary> Dictionaries { get; set; }

        public void Configure(EntityTypeBuilder<DataDictionaryCategory> entityBuilder, DbContext dbContext, Type dbContextLocator)
        {
            entityBuilder.UseDefaultTableNameDefine();

            entityBuilder.HasMany(p => p.Dictionaries)
                .WithOne(p => p.Category)
                .HasForeignKey(p => p.CategoryId);
        }
    }
}
